function getCookie(name) {
    var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
    return r ? r[1] : undefined;
}


$(function () {
    $(".input_sub").click(function (e) {

        // TODO 修改密码
        // 1、获取数据
        var old_password = $("#old_password").val()
        var new_password = $("#new_password").val()
        var re_new_password = $("#re_new_password").val()

        // 2、判断一下两次输入的密码是否一致
        if (new_password != re_new_password) {
            alert("两次密码输入有误")
            return
        }

        params = {
            old_password: old_password,
            new_password: new_password,
            re_new_password: re_new_password
        }

        $.ajax({
            url: "/user/pass_info",
            type: "post",
            contentType: "application/json",
            headers: {
                "X-CSRFToken": getCookie("csrf_token")
            },
            data: JSON.stringify(params),
            success: function (data) {
                if (data.errno == "0") {
                    alert("修改成功")
                    window.location.reload()
                } else {
                    alert(data.errmsg)
                }

            }
        })

    })
})